package com.webchat.chat.service.impl;

import com.webchat.chat.core.redis.RedisService;
import com.webchat.chat.core.tools.ChatConstant;
import com.webchat.chat.core.tools.SensitivewordFilter;
import com.webchat.chat.dao.SensitiveWordMapper;
import com.webchat.chat.model.SensitiveWord;
import com.webchat.chat.service.SensitiveWordService;
import com.webchat.chat.core.AbstractService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;


/**
 * Created by admin on 2018-07-03.
 */
@Service
@Transactional
public class SensitiveWordServiceImpl extends AbstractService<SensitiveWord> implements SensitiveWordService {
    @Resource
    private SensitiveWordMapper sensitiveWordMapper;
    @Resource
    private RedisService redisService;

    @Override
    public List<String> findAllWord() {

        return sensitiveWordMapper.findAllWord();
    }

    @Override
    public void saveSensitiveWord(SensitiveWord sensitiveWord) {
        super.save(sensitiveWord);
        List<String> sensitiveWords = sensitiveWordMapper.findAllWord();
        redisService.addList(ChatConstant.Project_Sensitive_Word,sensitiveWords);
        SensitivewordFilter.freshSensitiveWord();
    }
}
